﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BoletoElectronicoDesktop.AbmBeneficiarios
{
    public partial class FormSeleccionarPostnet : Form
    {
        public string numeroPostnet;
        public FormSeleccionarPostnet()
        {
            InitializeComponent();
        }

        private void FormSeleccionarPostnet_Load(object sender, EventArgs e)
        {
            //inicio con la ventana maximizada
            this.WindowState = FormWindowState.Maximized;

            cbModelo.Enabled = false;
        }

        private void cbMarca_Click(object sender, EventArgs e)
        {
            //cargo las marcas de los posibles postnets
            DataTable marcas = BeneficiarioDAO.ObtenerMarcas();
            cbMarca.DataSource = marcas;
            cbMarca.DisplayMember = "DescripcionMarca";
            cbMarca.ValueMember = "IdMarca";
            cbModelo.Enabled = true;
            cbModelo.DataSource = null;
        }

        private void cbModelo_Click(object sender, EventArgs e)
        {
            DataTable modelo = BeneficiarioDAO.ObtenerModelos(cbMarca.SelectedValue.ToString());
            cbModelo.DataSource = modelo;
            cbModelo.DisplayMember = "DescripcionModelo";
            cbModelo.ValueMember = "IdModelo";
        }

        private void btnLimpiar_Click(object sender, EventArgs e)
        {
            txtNumeroPostnet.Text = "";
            cbMarca.DataSource = null;
            cbModelo.DataSource = null;
            cbModelo.Enabled = false;
            dataGridView1.DataSource = null;
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            string numeroPn;
            string modelo;
            string marca;
            numeroPn = txtNumeroPostnet.Text;
            if (cbMarca.Text == "")
                marca = "";
            else
                marca = cbMarca.SelectedValue.ToString();
            if (cbModelo.Text == "")
                modelo = "";
            else
                modelo = cbModelo.SelectedValue.ToString();
            DataTable dt = BeneficiarioDAO.ObtenerPostnetsHabilitados(numeroPn, modelo, marca);
            dataGridView1.DataSource = dt;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //cargo la variable para pasarsela al otro formulario
            numeroPostnet = dataGridView1.CurrentRow.Cells["PostnetNumeroSerie"].Value.ToString();

            //cierro el formulario
            Close();
        }
    }
}
